package com.ushine.web.component.scheduled.config;

import org.quartz.*;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

/**
 * @Author: yls
 * @Date 2022/2/18 16:34
 * @Description: 创建job，统一参数
 * @Version 1.0
 **/
@Component
public class QuartzJobQuartzConfig {
    /**
     * 功能描述:
     * 〈  统一的job设置 〉
     *
     * @param generalCronJobClass 具体实施类
     * @param jobName             任务名称
     * @param jobGroupName        所属组名称
     * @return : org.quartz.JobDetail
     * @author : yls
     * @date : 2022/2/18 16:37
     */
    public JobDetail getJobDetail(Class<? extends QuartzJobBean> generalCronJobClass, String jobName, String jobGroupName) {
        return JobBuilder.newJob(generalCronJobClass).withIdentity(jobName, jobGroupName).storeDurably().build();
    }


    /**
     * 功能描述:
     * 〈统一的Trigger初始化〉
     *
     * @param jobDetail    job配置
     * @param jobName      任务名称
     * @param jobGroupName 所属组名称
     * @return : org.quartz.Trigger
     * @author : yls
     * @date : 2022/2/18 16:48
     */
    public Trigger getCronTrigger(JobDetail jobDetail, ScheduleBuilder scheduleBuilder,
                                  String jobName, String jobGroupName,
                                  String description) {
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail)
                .withIdentity(jobName, jobGroupName)
                .withSchedule(scheduleBuilder)
                .withDescription(description)
                .build();

    }
}
